package logic

import (
	"context"
	"product_zc/models/mysql"

	"product_zc/productRpc/internal/svc"
	"product_zc/productRpc/productRpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ClassUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewClassUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClassUpdateLogic {
	return &ClassUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ClassUpdateLogic) ClassUpdate(in *productRpc.ClassUpdateRequest) (*productRpc.ClassUpdateResponse, error) {
	// todo: add your logic here and delete this line

	class := mysql.Class{}
	mysql.DB.Where("userId=? and id=?", in.UserId, in.Id).Find(&class)

	class.ClassName = in.ClassName

	mysql.DB.Updates(&class)

	return &productRpc.ClassUpdateResponse{
		Id: int64(class.ID),
	}, nil
}
